import { networkRequest, baseRequestConfig, } from './RequestConfig'
//加解密
import { encryptMD5 } from "../crypt/index"
//uuid
import { v4 as uuidv4 } from 'uuid';

//获取用户信息
export const getUserInfo = (params) => {
    baseRequestConfig.url = '/push/main/000_000_000'
    baseRequestConfig.data = addPagams(params)
    return networkRequest(
        baseRequestConfig
    )
}

//创建推送任务
export const pushCase = (params) => {
    baseRequestConfig.url = '/push/main/000_000_001'
    baseRequestConfig.data = addPagams(params)
    return networkRequest(
        baseRequestConfig
    )
}

//获取推送记录记录
export const getRecords = (params) => {
    baseRequestConfig.url = '/push/main/000_000_002'
    baseRequestConfig.data = addPagams(params)
    return networkRequest(
        baseRequestConfig
    )
}


function addPagams(params) {
    //增加校验参数
    const timestamp = Date.now().toString();
    // 去除连字符，生成紧凑形式的UUID
    const nonce = uuidv4().replace(/-/g, '');
    const clientId = "web_app_v1";
    const version = "107";
    const securityKey = '766hQH';

    //签名按照顺序全小写再md5
    const signature = nonce.toLowerCase()
        + clientId.toLowerCase()
        + version.toLowerCase()
        + timestamp.toLowerCase()
        + securityKey

    params.set('timestamp', timestamp)
    params.set('nonce', nonce)
    params.set('clientId', clientId)
    params.set('version', version)
    params.set('signature', encryptMD5(signature))
    return params
}




